//
//  IDocFile.m
//  XRmenu
//
//  Created by yangxh on 11-3-24.
//  Copyright 2011 E0571. All rights reserved.
//

#import "IDocFile.h"


@implementation IDocFile

@synthesize fileName;
@synthesize downloadUrl;
@synthesize fileSize;

//=========================================================== 
// - (id)init
//
//=========================================================== 
- (id)init
{
	return [self initWithFileName:nil downloadUrl:nil fileSize:0];
}


//=========================================================== 
// - (id)initWith:
//
//=========================================================== 
- (id)initWithFileName:(NSString*)aFileName downloadUrl:(NSString*)aDownloadUrl fileSize:(NSInteger)aFileSize 
{
    self = [super init];
    if (self) {
        self.fileName = aFileName;
        self.downloadUrl = aDownloadUrl;
        self.fileSize = aFileSize;
    }
    return self;
}


//=========================================================== 
// + (id)objectWith:
//
//=========================================================== 
+ (id)objectWithFileName:(NSString*)aFileName downloadUrl:(NSString*)aDownloadUrl fileSize:(NSInteger)aFileSize  
{
    id result = [[[self class] alloc] initWithFileName:aFileName downloadUrl:aDownloadUrl fileSize:aFileSize];
	
    return [result autorelease];
}

//=========================================================== 
// - (NSArray *)keyPaths
//
//=========================================================== 
- (NSArray *)keyPaths
{
    NSArray *result = [NSArray arrayWithObjects:
					   @"fileName",
					   @"downloadUrl",
					   @"fileSize",
					   nil];
	
    return result;
}


//=========================================================== 
// - (NSString *)descriptionForKeyPaths
//
//=========================================================== 
- (NSString *)descriptionForKeyPaths 
{
    NSMutableString *desc = [NSMutableString string];
    NSEnumerator *e = [[self keyPaths] objectEnumerator];
    NSString *thisKey;
    [desc appendString:@"\n\n"];
	
    while ((thisKey = [e nextObject])) {
        [desc appendFormat: @"%@: %@\n", thisKey, [self valueForKey:thisKey]];
    }
	
    return [NSString stringWithString:desc];
}

- (NSString *)description
{
	return [self descriptionForKeyPaths];
}

//=========================================================== 
// dealloc
//=========================================================== 
- (void)dealloc
{
    [fileName release];
    fileName = nil;
    [downloadUrl release];
    downloadUrl = nil;
	
    [super dealloc];
}

+ (IDocFile *)iDocFileByParse:(NSDictionary *)info
{
	IDocFile *doc = [IDocFile objectWithFileName:[info objectForKey:@"FileName"] downloadUrl:[info objectForKey:@"FileUrl"] fileSize:dictInt(info,@"FileSize")];
	return doc;
}

@end
